function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
} 

function  fetch(url,response){ 
  showLoad();
  console.log(url)
    wx.request({
      url: url,
      data:{ 
      },  
  success:function(res){ 
  if(res.statusCode==200){ 
    console.log(res.data.data);
    console.log(res.data.status == 1);
        if (res.data.status == 1){
          console.log(res.data.data ); 
          response(res.data.data);  
         
        }else{
          failshow(res.msg);
        }
 

    
  }else{
      failshow();
  }


   
  },
  complete:function(){ 
    hideLoad();
  } 
});


}




function failshow(msg){ 
    wx.showToast({
      title: msg, 
      duration: 2000
    })

}


function showLoad(){
  wx.showLoading({
    title: 'loading',
  }) 
}
function hideLoad(){
  setTimeout(function () {
    wx.hideLoading()
  }, 200)
}










module.exports = {
  formatTime: formatTime ,
  fetch:fetch
  
}
